package com.zzxx.shooter;

import java.awt.image.BufferedImage;

public class Hero extends FlyingObject {
    private int life;
    private int doubleFire;
    private int index;
    private BufferedImage[] images;




    public Hero() {
        x = 200;
        y = 300;
        images = new BufferedImage[]{ShootGame.hero0, ShootGame.hero1};
        life = 3;
        width = images[0].getWidth();
        height = images[0].getHeight();
        index = 0;
        doubleFire = 0;
        emberImages = new BufferedImage[]{
                ShootGame.hero_ember0,
                ShootGame.hero_ember1,
                ShootGame.hero_ember2,
                ShootGame.hero_ember3,
        };

    }

    public Bullet[] shoot(){
        Bullet[] bs;
        if(doubleFire>0){
            bs = new Bullet[2];
            bs[0] = new Bullet(this.x+this.width/4,this.y);
            bs[1] = new Bullet(this.x+this.width*3/4,this.y);
            doubleFire-=2;
            return bs;
        }else {
            bs = new Bullet[1];
            bs[0] = new Bullet(this.x+this.width/2,this.y);
            return bs;
        }
    }
    @Override
    public void step() {
        image = images[index++/10%2];
    }
    public int getLife() {
        return life;
    }

    public void addLife() {
        this.life++;
    }

    public int getDoubleFire() {
        return doubleFire;
    }

    public void setDoubleFire() {
        this.doubleFire += 20;
    }

    public void subtractLife(){
        this.life--;
    }

    public void moveTo(int x,int y){
        this.setX(x);
        this.setY(y);
    }

//    public Bullet[] shoot(){}

    public boolean hit(FlyingObject a){
        return true;
    }
    public boolean outOfBound(){
        return true;
    }

    public boolean crash(FlyingObject other){
        int x = other.getX();
        int y = other.getY();
        return this.x+this.width>x && this.x<x+other.width && this.y+this.height>y && this.y<y+other.height;
    }


}
